<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------

namespace api\admin\model;

use api\common\model\CommonModel;
use think\cache\driver\Redis;

class  BandToiletTagModel extends CommonModel
{
    // 可查询字段
    // protected $visible = [
    //     'id', 'start_time', 'end_time', 'man_num', 'woman_num','flow_num','titile','position','create_time',
    // ];
    //模型关联方法
    // protected $relationFilter = ['articles'];

    /**
     * 基础查询
     */
    // protected function base($query)
    // {
    //     $query->alias(' BandToiletTag')->where(' BandToiletTag.status', 1);
    // }
    /**
     * 关联
     * @return $this
     */
    // public function articles()
    // {
    //     return $this->belongsToMany('PortalPostModel','portal_tag_post','post_id','tag_id');
    // }

    
    /**
     * [get BandToiletTagFields 获取单个公厕信息]
     * @Author   HUI
     * @DateTime 2018-11-27
     * @version  [version]
     * @param    [type]     $id     [description]
     * @param    string     $fields [description]
     * @return   [type]             [description]
     */
    public function getBandToiletTagFields($id, $fields = '*')
    {
        if (is_array($id)) {
            return $this->field($fields)->where($id)->find();

        } else {
            return $this->field($fields)->where('id', $id)->find();
        }

    }


    /**
     * [get BandToiletTagFields 更新单个公厕信息]
     * @Author   HUI
     * @DateTime 2018-11-27
     * @version  [version]
     * @param    [type]     $id     [description]
     * @param    string     $fields [description]
     * @return   [type]             [description]
     */
    public function updateBandToiletTagFields($id, $update = [])
    {

        if (is_array($id)) {
            return $this->where($id)->update($update);
        } else {
            return $this->where('id', $id)->update($update);
        }
    }

    /**
     * [addToiletTag 添加tag数据到redis]
     * @Author   HUI
     * @DateTime 2018-12-03
     * @version  [version]
     * @param    string     $value [description]
     */
    public function addToiletTags($value='')
    {
        $Redis = new Redis();
        return $Redis->set('toiletTag',serialize($this->select()->toArray()));
    }

}
